﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;

namespace CarManager.DA_Layer
{
    class Data_Access_Helper
    {
        /// <summary>
        /// Khai bao cac du lieu can thiet:
        /// </summary>

        SqlConnection conn;

        public static string chuoi = ConfigurationSettings.AppSettings["config"];
        //Khoi tao ket noi khi goi ham
        public Data_Access_Helper()
        {
            conn = new SqlConnection(chuoi);
        }

        /// <summary>
        /// Mo, ngat, kiem tra ket noi CSDL
        /// </summary>
        public void Open()
        {
            if (conn.State == ConnectionState.Closed)
                conn.Open();
        }
        public void Close()
        {
            if (conn.State == ConnectionState.Open)
                conn.Close();
        }
        public bool TestConnect()
        {
            try
            {
                Open();
                return true;
            }
            catch
            {
                Close();
                MessageBox.Show("Can not connect to Database!", "Error");
                return false;
            }
        }

    }
}
